import { Injectable } from '@nestjs/common';
import * as Redis from 'ioredis';
import * as _ from 'lodash';
import { ConfigService } from '@nestjs/config';


@Injectable()
export class RedisService {
  readonly client: Redis.Redis;

  constructor(private readonly configService: ConfigService) {
    this.client = new Redis(this.configService.get('redis'));
  }

    //获取值的方法
  async setCache(key: string, value: string, expire: number) {
    return await this.client.set(key, value, 'EX', expire);
  }

  async getCache(key: string) {
    return await this.client.get(key);
  }

  async delCache(key: string) {
    return await this.client.del(key);
  }
}